package com.ihd.ihardware.common.widget;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.ihd.ihardware.R;
import com.ihd.ihardware.pojo.MembersRes;

import java.util.List;


public class MemberDialog extends Dialog {
    private Activity mActivity;
    private List<MembersRes.DataBean> mData;
    private RecyclerView mBottomListRV;
    private ImageView cancelIV;
    private MemberDialogListAdapter.OnItemClickListener mItemClickListener = null;


    public MemberDialog(Activity activity, int theme, List<MembersRes.DataBean> data, MemberDialogListAdapter.OnItemClickListener itemClickListener) {
        super(activity, theme);
        mData = data;
        mActivity = activity;
        mItemClickListener = itemClickListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View root = LayoutInflater.from(mActivity).inflate(R.layout.dialog_pop_member, null);
        setContentView(root);
        cancelIV = root.findViewById(R.id.cancel);
        mBottomListRV = root.findViewById(R.id.dataRV);
        mBottomListRV.setLayoutManager(new LinearLayoutManager(mActivity));
        MemberDialogListAdapter mDialogListAdapter = new MemberDialogListAdapter(mActivity, mData);
        mDialogListAdapter.setOnItemClickListener(mItemClickListener);
        mBottomListRV.setAdapter(mDialogListAdapter);
        cancelIV.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cancel();
            }
        });
        setCancelable(true);
        setCanceledOnTouchOutside(true);

        Window dialogWindow = getWindow();
        dialogWindow.setGravity(Gravity.TOP | Gravity.LEFT);
//        dialogWindow.setWindowAnimations(R.style.popupAnimation);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        root.measure(0, 0);
        lp.width = root.getMeasuredWidth();
        lp.height = root.getMeasuredHeight();
        dialogWindow.setAttributes(lp);
    }
}
